{"componentChunkName":"component---src-templates-post-jsx","path":"/[BOJ]15685/","result":{"data":{"site":{"siteMetadata":{"title":"SUbbb"}},"markdownRemark":{"id":"6a79cddd-dc1b-5e34-8a84-af313c37de0e","excerpt":"문제 드래곤 커브는 다음과 같은 세 가지 속성으로 이루어져 있으며, 이차원 좌표 평면 위에서 정의된다. 좌표 평면의 x축은 → 방향, y축은 ↓ 방향이다. 시작 점 시작 방향 세대 0세대 드래곤 커브는 아래 그림과 같은 길이가 1인 선분이다. 아래 그림은 (0, 0)에서 시작하고, 시작 방향은 오른쪽인 0세대 드래곤 커브이다. 1세대 드래곤 커브는 0세대…","html":"<h2>문제</h2>\n<p>드래곤 커브는 다음과 같은 세 가지 속성으로 이루어져 있으며, 이차원 좌표 평면 위에서 정의된다. 좌표 평면의 x축은 → 방향, y축은 ↓ 방향이다.</p>\n<ol>\n<li>시작 점</li>\n<li>시작 방향</li>\n<li>세대</li>\n</ol>\n<p>0세대 드래곤 커브는 아래 그림과 같은 길이가 1인 선분이다. 아래 그림은 (0, 0)에서 시작하고, 시작 방향은 오른쪽인 0세대 드래곤 커브이다.</p>\n<img src='http://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/15685/1.png' width='30%'>\n<p>1세대 드래곤 커브는 0세대 드래곤 커브를 끝 점을 기준으로 시계 방향으로 90도 회전시킨 다음 0세대 드래곤 커브의 끝 점에 붙인 것이다. 끝 점이란 시작 점에서 선분을 타고 이동했을 때, 가장 먼 거리에 있는 점을 의미한다.</p>\n<img src='https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/15685/2.png' width='30%'>\n<p>2세대 드래곤 커브도 1세대를 만든 방법을 이용해서 만들 수 있다. (파란색 선분은 새로 추가된 선분을 나타낸다)</p>\n<img src='https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/15685/3.png' width='30%'>\n<p>3세대 드래곤 커브도 2세대 드래곤 커브를 이용해 만들 수 있다. 아래 그림은 3세대 드래곤 커브이다.</p>\n<img src='https://onlinejudgeimages.s3-ap-northeast-1.amazonaws.com/problem/15685/4.png' width='30%'>\n<p>즉, K(K > 1)세대 드래곤 커브는 K-1세대 드래곤 커브를 끝 점을 기준으로 90도 시계 방향 회전 시킨 다음, 그것을 끝 점에 붙인 것이다.</p>\n<p>크기가 100×100인 격자 위에 드래곤 커브가 N개 있다. 이때, 크기가 1×1인 정사각형의 네 꼭짓점이 모두 드래곤 커브의 일부인 정사각형의 개수를 구하는 프로그램을 작성하시오. 격자의 좌표는 (x, y)로 나타내며, 0 ≤ x ≤ 100, 0 ≤ y ≤ 100만 유효한 좌표이다.</p>\n<h2>입, 출력</h2>\n<p>입력</p>\n<ul>\n<li>첫째 줄에 드래곤 커브의 개수 N(1 ≤ N ≤ 20)이 주어진다. 둘째 줄부터 N개의 줄에는 드래곤 커브의 정보가 주어진다. 드래곤 커브의 정보는 네 정수 x, y, d, g로 이루어져 있다. x와 y는 드래곤 커브의 시작 점, d는 시작 방향, g는 세대이다. (0 ≤ x, y ≤ 100, 0 ≤ d ≤ 3, 0 ≤ g ≤ 10)</li>\n<li>입력으로 주어지는 드래곤 커브는 격자 밖으로 벗어나지 않는다. 드래곤 커브는 서로 겹칠 수 있다.</li>\n<li>\n<p>방향은 0, 1, 2, 3 중 하나이고, 다음을 의미한다.</p>\n<ul>\n<li>0: x좌표가 증가하는 방향 (→)</li>\n<li>1: y좌표가 감소하는 방향 (↑)</li>\n<li>2: x좌표가 감소하는 방향 (←)</li>\n<li>3: y좌표가 증가하는 방향 (↓)</li>\n</ul>\n</li>\n</ul>\n<p>출력</p>\n<ul>\n<li>첫째 줄에 크기가 1×1인 정사각형의 네 꼭짓점이 모두 드래곤 커브의 일부인 것의 개수를 출력한다.</li>\n</ul>\n<h3>📍 <strong>Logic</strong></h3>\n<deckgo-highlight-code language=\"java\" terminal=\"carbon\" theme=\"a11y-dark\" line-numbers=\"true\"  >\n          <code slot=\"code\">class DragonMap {\n    int[][] map = new int[101][101];\n    int[] rangeX = { 1, 0, -1, 0 };\n    int[] rangeY = { 0, -1, 0, 1 };\n    ...\n\n}</code>\n        </deckgo-highlight-code>\n<ul>\n<li>드래곤 커브를 그리기 위한 <code class=\"language-text\">map</code> 과 방향에 따른 이동을 위해 사용하는 범위 정보를 저장하는 클래스</li>\n</ul>\n<deckgo-highlight-code language=\"java\" terminal=\"carbon\" theme=\"a11y-dark\" line-numbers=\"true\"  >\n          <code slot=\"code\">public void drawDragonCurves(int x, int y, int d, int g) {\n    List&lt;Integer&gt; dirList = new ArrayList&lt;&gt;();\n    dirList.add(d);\n\n    for (int i = 0; i &lt; g; i++) {\n        for (int j = dirList.size() - 1; j &gt;= 0; j--) {\n            dirList.add(getCountClockDir(dirList.get(j)));\n        }\n    }\n\n    map[x][y] = 1;\n    for (Integer dir : dirList) {\n        x += rangeX[dir];\n        y += rangeY[dir];\n        map[x][y] = 1;\n    }\n}</code>\n        </deckgo-highlight-code>\n<ul>\n<li>리스트에 방향 정보를 저장하고, 마지막에 저장한 방향 정보부터 차례로 반시계 방향으로 돌린 방향 정보를 저장한다.</li>\n</ul>\n<h3>📄 <strong>CODE</strong></h3>\n<details>\n  <summary>코드 보기/접기💫</summary>\n    <div markdown=\"1\">\n<deckgo-highlight-code  terminal=\"carbon\" theme=\"a11y-dark\" line-numbers=\"true\"  >\n          <code slot=\"code\">import java.io.BufferedReader;\nimport java.io.IOException;\nimport java.io.InputStreamReader;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\n\nclass DragonMap {\n    int[][] map = new int[101][101];\n    int[] rangeX = { 1, 0, -1, 0 };\n    int[] rangeY = { 0, -1, 0, 1 };\n\n    public void drawDragonCurves(int x, int y, int d, int g) {\n        List&lt;Integer&gt; dirList = new ArrayList&lt;&gt;();\n        dirList.add(d);\n\n        for (int i = 0; i &lt; g; i++) {\n            for (int j = dirList.size() - 1; j &gt;= 0; j--) {\n                dirList.add(getCountClockDir(dirList.get(j)));\n            }\n        }\n\n        map[x][y] = 1;\n        for (Integer dir : dirList) {\n            x += rangeX[dir];\n            y += rangeY[dir];\n            map[x][y] = 1;\n        }\n    }\n\n    public int countSquares() {\n        int counts = 0;\n\n        for (int i = 0; i &lt; 100; i++) {\n            for (int j = 0; j &lt; 100; j++) {\n                if (map[i][j] == 1 &amp;&amp; map[i][j + 1] == 1 &amp;&amp; map[i + 1][j] == 1 &amp;&amp; map[i + 1][j + 1] == 1) {\n                    counts++;\n                }\n            }\n        }\n\n        return counts;\n    }\n\n    private int getCountClockDir(int dir) {\n        return (dir + 1) % 4;\n    }\n}\n\npublic class Main {\n    public static void main(String[] args) throws IOException {\n        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\n\n        int N = Integer.parseInt(br.readLine());\n\n        DragonMap dragons = new DragonMap();\n\n        for (int i = 0; i &lt; N; i++) {\n            int[] info = Arrays.stream(br.readLine().split(&quot; &quot;)).mapToInt(Integer::parseInt).toArray();\n            dragons.drawDragonCurves(info[0], info[1], info[2], info[3]);\n        }\n        br.close();\n\n        System.out.println(dragons.countSquares());\n    }\n}</code>\n        </deckgo-highlight-code>\n  \t</div>\n</details>\n<h3>✏️ <strong>Review</strong></h3>\n<ul>\n<li>매 세대마다 방향이 바뀌는 것에 대해, 이를 리스트에 저장하고 계속 업데이트해주는 방식은 생각했지만, 왜인지 리스트도 큐처럼 <code class=\"language-text\">push</code> , <code class=\"language-text\">pop</code> 을 해야 하니까 비효율적이지 않나 ... 하는 생각에 사로잡혀 혼자 꽉 막혀버렸다.</li>\n<li>다른 방법은 뭐가 있나 싶어 한 블로그를 봤는데, 생각한 그대로를 구현한 글을 발견해서 나의 무지함을 깨달았다.</li>\n</ul>\n<h3>📕 출처</h3>\n<ul>\n<li>Baekjoon : <a href=\"https://www.acmicpc.net/problem/15685\">https://www.acmicpc.net/problem/15685</a></li>\n<li><a href=\"https://velog.io/@hammii/%EB%B0%B1%EC%A4%80-15685-%EB%93%9C%EB%9E%98%EA%B3%A4-%EC%BB%A4%EB%B8%8C-java\">15685</a></li>\n</ul>","frontmatter":{"title":"👩‍💻 15685. 드래곤 커브","date":"March 30, 2022","update":"March 30, 2022","tags":["구현","시뮬레이션"],"series":"👩‍💻 BOJ"},"fields":{"slug":"/[BOJ]15685/","readingTime":{"minutes":6.495}}},"seriesList":{"edges":[{"node":{"id":"27733333-3aad-5771-a1a1-27b4de4b4a01","fields":{"slug":"/[BOJ]2225/"},"frontmatter":{"title":"👩‍💻 2225. 합분해"}}},{"node":{"id":"548ba188-2afe-5575-b79f-107c6c65b07d","fields":{"slug":"/[BOJ]1012/"},"frontmatter":{"title":"👩‍💻 1012. 유기농 배추"}}},{"node":{"id":"0c712680-130f-5fa5-8c3b-3632dd5d1af0","fields":{"slug":"/[BOJ]1260/"},"frontmatter":{"title":"👩‍💻 1260. DFS와 BFS"}}},{"node":{"id":"0e07a592-06ce-5e01-b5e1-95398330372e","fields":{"slug":"/[BOJ]1707/"},"frontmatter":{"title":"👩‍💻 1707. 이분그래프"}}},{"node":{"id":"df12bfec-ed5c-5fc4-8442-0a4b3f9759a3","fields":{"slug":"/[BOJ]2668/"},"frontmatter":{"title":"👩‍💻 2668. 숫자 고르기"}}},{"node":{"id":"01bbb6dc-812c-5223-87c5-53bf04c0d0a6","fields":{"slug":"/[BOJ]9466/"},"frontmatter":{"title":"👩‍💻 9466. 텀 프로젝트"}}},{"node":{"id":"abc306b3-c3a6-552a-8979-e82d506b3921","fields":{"slug":"/[BOJ]2146/"},"frontmatter":{"title":"👩‍💻 2146. 다리 만들기"}}},{"node":{"id":"b3394e53-5e9a-595e-8da4-bb3debd220c0","fields":{"slug":"/[BOJ]5014/"},"frontmatter":{"title":"👩‍💻 5014. 스타트 링크"}}},{"node":{"id":"be297703-e778-5727-8019-6954bc95da3a","fields":{"slug":"/[BOJ]11559/"},"frontmatter":{"title":"👩‍💻 11559. Puyo Puyo"}}},{"node":{"id":"ddf11545-d468-5269-94b1-5daa2720e886","fields":{"slug":"/[BOJ]17471/"},"frontmatter":{"title":"👩‍💻 17471. 게리맨더링"}}},{"node":{"id":"8d77114d-fc6e-5de2-a3ca-c3b250425a56","fields":{"slug":"/[BOJ]2437/"},"frontmatter":{"title":"👩‍💻 2437. 저울"}}},{"node":{"id":"9a8942ce-552f-51ae-b304-0d0fab8f2eba","fields":{"slug":"/[BOJ]14891/"},"frontmatter":{"title":"👩‍💻 14891. 톱니바퀴"}}},{"node":{"id":"f1c04e8a-df0a-5294-949f-5f3a483cbcb0","fields":{"slug":"/[BOJ]14503/"},"frontmatter":{"title":"👩‍💻 14503. 로봇 청소기"}}},{"node":{"id":"883b6ecf-7528-5c16-92fa-edf12a64e80e","fields":{"slug":"/[BOJ]3190/"},"frontmatter":{"title":"👩‍💻 3190. 뱀"}}},{"node":{"id":"099b2576-7d05-5872-a9f0-f1ee6efd3a9a","fields":{"slug":"/[BOJ]14502/"},"frontmatter":{"title":"👩‍💻 14502. 연구소"}}},{"node":{"id":"50eef059-4e55-5f14-a9cf-fb01b6506f02","fields":{"slug":"/[BOJ]17779/"},"frontmatter":{"title":"👩‍💻 17779. 게리맨더링 2"}}},{"node":{"id":"aa67d90b-4801-574c-b225-56c23737a5e2","fields":{"slug":"/[BOJ]2579/"},"frontmatter":{"title":"👩‍💻 2579. 계단 오르기"}}},{"node":{"id":"9db6b43b-963a-5ebd-b72b-69936cf37858","fields":{"slug":"/[BOJ]14499/"},"frontmatter":{"title":"👩‍💻 14499. 주사위 굴리기"}}},{"node":{"id":"6a79cddd-dc1b-5e34-8a84-af313c37de0e","fields":{"slug":"/[BOJ]15685/"},"frontmatter":{"title":"👩‍💻 15685. 드래곤 커브"}}},{"node":{"id":"5e001d34-d985-545b-83ec-7f1c7caea286","fields":{"slug":"/[BOJ]17144/"},"frontmatter":{"title":"👩‍💻 17144. 미세먼지 안녕!"}}},{"node":{"id":"1d132410-9377-5e55-85b9-4664ff64de73","fields":{"slug":"/[BOJ]9935/"},"frontmatter":{"title":"👩‍💻 9935. 문자열 폭발"}}},{"node":{"id":"e13ff8d6-9b02-56c0-83e2-1d3144f70e1d","fields":{"slug":"/[BOJ]16472/"},"frontmatter":{"title":"👩‍💻 16472. 고냥이"}}},{"node":{"id":"0f782160-aaa9-5c54-80c0-72a15172dd16","fields":{"slug":"/[BOJ]1083/"},"frontmatter":{"title":"👩‍💻 1083. 소트"}}},{"node":{"id":"fef58615-9e18-5f50-8d09-3d1e2839342f","fields":{"slug":"/[BOJ]20922/"},"frontmatter":{"title":"👩‍💻 20922. 겹치는 건 싫어"}}},{"node":{"id":"7ca89240-c65f-5cb4-aeef-c5f1605ebd00","fields":{"slug":"/[BOJ]16172/"},"frontmatter":{"title":"👩‍💻 16172. 나는 친구가 적다(Large)"}}}]},"previous":{"fields":{"slug":"/[JPA]10/"},"frontmatter":{"title":"📚 10. 객체지향 쿼리 언어"}},"next":{"fields":{"slug":"/[면접]JVM 동작원리/"},"frontmatter":{"title":"💬 JVM 동작원리"}}},"pageContext":{"id":"6a79cddd-dc1b-5e34-8a84-af313c37de0e","series":"👩‍💻 BOJ","previousPostId":"a41dc548-d976-533a-a680-96e86a627d35","nextPostId":"6290497a-5cc5-5d95-929c-9ba705a61206"}},"staticQueryHashes":[]}